home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93c.txt / 000018_icon-group-sender _Tue Jul 20 21:35:06 1993.msg < prev    next >
Internet Message Format  |  1994-02-02  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Tue, 20 Jul 1993 19:44:55 MST
  2. Date: Tue, 20 Jul 93 21:35:06 EDT
  3. From: Paul_Abrahams@MTS.cc.Wayne.edu
  4. To: icon-group@cs.arizona.edu
  5. Message-Id: <706461@MTS.cc.Wayne.edu>
  6. Subject: Mysteries of "every"
  7. Status: R
  8. Errors-To: icon-group-errors@cs.arizona.edu
  9.  
  10.  
  11. Cary Coutant wrote the following in response to my query:
  12. -----------------------------
  13.  >    every retval :=  8 * retval + ord(!s) - ord("0")
  14.  >
  15.  > Now the output of the program is 3 (the last digit), not 83.
  16.  >
  17.  > Can anyone explain to me what's going on?
  18.  
  19.  Try reversing the operands of the "+" operation:
  20.  
  21.      every retval := ord(!s) - ord("0") + 8 * retval
  22.  
  23.  Your problem was that the every was resuming the expression
  24.  from the last suspended generator, so "8 * retval" was never
  25.  being reevaluated.
  26.  
  27.  In situations like this, it's sometimes useful to replace a
  28.  built-in operator with your own procedure, so you can see
  29.  what's going on by setting TRACE.  For example:
  30.  
  31.      every retval :=  add(8 * retval, ord(!s) - ord("0"))
  32. -----------------------------------
  33.  
  34. This explanation satisfies the ultimate test: Cary's version works.
  35.  
  36. Yet I've looked again at pages 15-16 of the Icon book and I still don't
  37. get it.  The explanation of resumption on p. 15 is in terms of failure,
  38. and there's no failure in the expression of my example.  The description
  39. of "every" on p. 16 says that "expr1 is first evaluated and then
  40. repeatedly resumed to produce all its values."  I would have thought that
  41. resuming an expression that doesn't fail would cause it to be
  42. =completely= reevaluated.
  43.  
  44. Clearly the assignment, which is the outermost level of the expression,
  45. is evaluated on each iteration.  In fact, I verified (by attaching a
  46. "do") that with s="123", retval takes on successive values of 1,2,3.  Yet
  47. the second retval is not being reevaluated.  So which parts of an
  48. expression are reevaluated and which ones aren't?  Is there any way to
  49. deduce what happens from the explanation in the Icon book?
  50.  
  51. I'd appreciate any help I can get on this.  I'd also suggest that you
  52. post your comments to icon-group rather than sending them to me
  53. personally.
  54.  
  55. Paul Abrahams
  56. Reply-To: abrahams@acm.org
  57.